Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to trigger a Quartz job on-demand through an Actuator endpoint #43086

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nosan
Copy link
Contributor

@nosan nosan commented Nov 10, 2024

Before this commit, triggering a Quartz job on demand was not possible. This commit introduces a new @WriteOperation endpoint at /actuator/quartz/jobs/{groupName}/{jobName}/trigger, allowing a job to be triggered by specifying the {jobName}, {groupName}, and an optional JobDataMap.

See gh-42530

$ curl 'http://localhost:8080/actuator/quartz/jobs/samples/jobOne/trigger' -i -X POST \
    -H 'Content-Type: application/json' \
    -d '{"jobData":{"key":"value","keyN":"valueN"}}'
    
HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 166

{
  "group" : "samples",
  "name" : "jobOne",
  "className" : "org.springframework.scheduling.quartz.DelegatingJob",
  "triggerTime" : "2024-11-10T09:44:05.425233Z"
}

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 10, 2024
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 12, 2024
@philwebb philwebb added this to the 3.5.x milestone Nov 12, 2024
@nosan nosan force-pushed the 42530 branch 2 times, most recently from c20c53d to 8dbd473 Compare November 14, 2024 13:21
@@ -298,7 +298,7 @@ protected interface LinksHandler {
@FunctionalInterface
protected interface ReactiveWebOperation {

Mono<ResponseEntity<Object>> handle(ServerWebExchange exchange, Map<String, String> body);
Mono<ResponseEntity<Object>> handle(ServerWebExchange exchange, Map<String, Object> body);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you had to change this?

Copy link
Contributor Author

@nosan nosan Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment regarding these changes in the #42530 (comment)

The Map<String, String> request body does not support complex values like Map or List, only basic JSON types.

For example, this JSON is not supported at the moment:

{
  "jobData": {
    "key": "value"
  }
}

WebMvc:

[org.springframework.http.converter.HttpMessageNotReadableException: 
JSON parse error: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)]

WebFlux:

org.springframework.core.codec.DecodingException: JSON decoding error: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we don't intend to support arbitrary input this way. This part is covered in the reference guide.

Can you please revert to allow jobs to be invoked on demand without custom data?

In the comment you've referenced you stated that "By the way, Jersey works fine". I am not sure what you mean by that but if there is something that needs to be done for things to work currently the same way on all stacks, please create a separate issue with more details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that @WebEndpointTest with JERSEY infrastructure does support Map<String, Object as an endpoint parameter.

If I revert my changes related to @RequestBody Map<String, Object the MVC and WebFlux will fail but Jersey will not.

You can reproduce this issue by running this test QuartzEndpointWebIntegrationTests.quartzTriggerJobWithCustomData

Branch: https://github.com/nosan/spring-boot/tree/42530-map-issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nosan, I've created #43209 and reproduced the problem.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Nov 18, 2024
@nosan nosan force-pushed the 42530 branch 2 times, most recently from 860d875 to 709aa31 Compare November 18, 2024 16:55
… endpoint

Before this commit, triggering a Quartz job on demand was not possible.
This commit introduces a new @WriteOperation endpoint
at /actuator/quartz/jobs/{groupName}/{jobName}/trigger,
allowing a job to be triggered by specifying the jobName and groupName

See spring-projectsgh-42530
@nosan
Copy link
Contributor Author

nosan commented Nov 18, 2024

Thanks, @snicoll
PR has been updated.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants